<?php

namespace App\Jobs;

use App\Wen\Utils\Settings;
use App\Wen\Utils\UserUtils;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class UserRegisterAfterJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public $tries = 1;
    protected $user_id = 0;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user_id)
    {
        //
        $this->user_id = $user_id;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //
        if(_empty_($this->user_id)){
            return;
        }
        $first_welcome = Settings::get('app_login_first_welcome', '', true);
        if(mb_strlen($first_welcome) >= 2){
            UserUtils::add_user_notice(1001, $this->user_id, Settings::get('app_login_first_welcome_title', '欢迎来到'.Settings::get('app_title', '这'), true), $first_welcome, 100);
        }
        $default_plates = Settings::get('app_login_default_plates', '', true);
        if($default_plates){
            $default_plates = explode(',', $default_plates);
            foreach ($default_plates as $plate_id){
                UserUtils::add_user_plate($this->user_id, $plate_id);
            }
        }

        $first_chat = Settings::get('app_notice_assistant_first', '您好，很高兴认识您，自我介绍一下，我是您的专职小秘书，以后有些事情，由我负责通知您哦！', true);
        if($first_chat){
            UserUtils::assistant_notice($this->user_id, $first_chat);
        }
    }
}
